<!DOCTYPE html><html lang="zh"><head><meta name="generator" content="Hexo 3.8.0"><meta charset="utf-8"><title>通关Githug(二) - i蝸居年華_谢谢谢_CODE_HOME</title><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta name="description" content="[TOC] 继续上一篇通关Githug(一))"><meta name="keywords" content="Git"><meta property="og:type" content="article"><meta property="og:title" content="通关Githug(二)"><meta property="og:url" content="https://xiefayang.com/2017/12/25/通关Githug(二)/index.html"><meta property="og:site_name" content="i蝸居年華_谢谢谢_CODE_HOME"><meta property="og:description" content="[TOC] 继续上一篇通关Githug(一))"><meta property="og:locale" content="zh-CN"><meta property="og:updated_time" content="2019-05-21T03:16:16.546Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="通关Githug(二)"><meta name="twitter:description" content="[TOC] 继续上一篇通关Githug(一))"><link rel="icon" href="/images/favicon.svg"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css"><link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/5.4.1/css/all.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/atom-one-dark.css"><style>body>.footer,body>.navbar,body>.section{opacity:0}</style><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css"><link rel="stylesheet" href="/css/back-to-top.css"><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="//hm.baidu.com/hm.js?b59777544dd5d59ce94e191bac62427c";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><link rel="stylesheet" href="/css/progressbar.css"><script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><link rel="stylesheet" href="/css/style.css"></head><body class="is-3-column"><nav class="navbar navbar-main"><div class="container"><div class="navbar-brand is-flex-center"> <a class="navbar-item navbar-logo" href="/"><img src="/images/maotouying.svg" alt="通关Githug(二)" height="28"> <span style="font-size:16px;display:inline-block;vertical-align:top;font-weight:600">i蝸居年華_谢谢谢</span></a></div><div class="navbar-menu"><div class="navbar-start"> <a class="navbar-item" href="/">首页</a> <a class="navbar-item" href="/archives">归档</a> <a class="navbar-item" href="/categories">分类</a> <a class="navbar-item" href="/tags">标签</a> <a class="navbar-item" href="/about">关于</a></div><div class="navbar-end"><a class="navbar-item is-hidden-tablet catalogue" title="文章目录" href="javascript:;"><i class="fas fa-list-ul"></i></a><a class="navbar-item search" title="搜索" href="javascript:;"><div class="box01"> <input type="text" id="tip" placeholder="You Know, for Search~"><i class="search_icon"></i></div></a></div></div></div></nav><section class="section"><div class="container"><div class="columns"><div class="column is-8-tablet is-8-desktop is-9-widescreen has-order-2 column-main"><div class="card"><div class="card-content article"><div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto"><div class="level-left"> <span style="color:#7a7a7a!important">写于2017-12-25 12:39:05&nbsp;&nbsp;&nbsp;</span><div class="level-item"> <a class="has-link-grey -link" href="/categories/工具-版本管理/">工具 & 版本管理</a></div> <span class="level-item has-text-grey">40 分钟 读完 (大约 5976 个字)</span><span class="level-item has-text-grey" id="busuanzi_container_page_pv"><i class="far fa-eye"></i> <span id="busuanzi_value_page_pv">0</span>次访问</span></div></div><h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal"> 通关Githug(二)</h1><div class="content"><p>[TOC]</p><p>继续上一篇<a href="https://xiefayang.com/2017/12/25/通关Githug(一">通关Githug(一)</a>)</p><a id="more"></a><h4 id="关卡列表"><a href="#关卡列表" class="headerlink" title="关卡列表"></a>关卡列表</h4><p>再附上30-55关目录</p><table><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>关卡名称</strong></td><td><strong>学习内容</strong></td><td><strong>Git 命令</strong></td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-30.html" target="_blank" rel="noopener">第30关 blame</a></td><td>查询每一行代码被谁编辑过</td><td>git blame</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-31.html" target="_blank" rel="noopener">第31关 branch</a></td><td>创建分支</td><td>git branch</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-32.html" target="_blank" rel="noopener">第32关 checkout</a></td><td>切换分支</td><td>git checkout</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-33.html" target="_blank" rel="noopener">第33关 checkout_tag</a></td><td>切换到标签</td><td>git checkout</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-34.html" target="_blank" rel="noopener">第34关 checkout_tag_over_branch</a></td><td>切换到标签</td><td>git checkout</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-35.html" target="_blank" rel="noopener">第35关 branch_at</a></td><td>在指定的提交处创建分支</td><td>git branch</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-36.html" target="_blank" rel="noopener">第36关 delete_branch</a></td><td>删除分支</td><td>git branch -d</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-37.html" target="_blank" rel="noopener">第37关 push_branch</a></td><td>推送分支到远程仓库</td><td>git push</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-38.html" target="_blank" rel="noopener">第38关 merge</a></td><td>合并分支</td><td>git merge</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-39.html" target="_blank" rel="noopener">第39关 fetch</a></td><td>从远程仓库抓取数据</td><td>git fetch</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-40.html" target="_blank" rel="noopener">第40关 rebase</a></td><td>变基合并</td><td>git rebase</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-41.html" target="_blank" rel="noopener">第41关 repack</a></td><td>重新打包</td><td>git repack</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-42.html" target="_blank" rel="noopener">第42关 cherry-pick</a></td><td>合并分支上指定的提交</td><td>git cherry-pick</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-43.html" target="_blank" rel="noopener">第43关 grep</a></td><td>搜索文本</td><td>git grep</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-44.html" target="_blank" rel="noopener">第44关 rename_commit</a></td><td>修改历史提交的说明</td><td>git rebase -i</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-45.html" target="_blank" rel="noopener">第45关 squash</a></td><td>把多次提交合并成一次提交</td><td>git rebase -i</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-46.html" target="_blank" rel="noopener">第46关 merge_squash</a></td><td>合并分支时把多次提交合并成一次提交</td><td>git merge –squash</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-47.html" target="_blank" rel="noopener">第47关 reorder</a></td><td>调整提交顺序</td><td>git rebase -i</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-48.html" target="_blank" rel="noopener">第48关 bisect</a></td><td>用二分法定位 bug</td><td>git bisect</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-49.html" target="_blank" rel="noopener">第49关 stage_lines</a></td><td>添加文件的部分行到暂存区</td><td>git add –edit</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-50.html" target="_blank" rel="noopener">第50关 file_old_branch</a></td><td>查看 Git 上的操作历史</td><td>git reflog</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-51.html" target="_blank" rel="noopener">第51关 revert</a></td><td>取消已推送到远程仓库的提交</td><td>git revert</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-52.html" target="_blank" rel="noopener">第52关 restore</a></td><td>恢复被删除的提交</td><td>git reset –hard</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-53.html" target="_blank" rel="noopener">第53关 conflict</a></td><td>解决冲突</td><td></td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-54.html" target="_blank" rel="noopener">第54关 submodule</a></td><td>把第三方库当作子模块</td><td>git submodule</td></tr><tr><td><a href="http://wiki.jikexueyuan.com/project/githug-walkthrough/level-55.html" target="_blank" rel="noopener">第55关 contribute</a></td><td>捐献</td></tr></tbody></table><h4 id="Level-30-blame"><a href="#Level-30-blame" class="headerlink" title="Level 30: blame"></a>Level 30: blame</h4><blockquote><p>Someone has put a password inside the file ‘config.rb’ find out who it was.</p><p>有人在config.rb文件里放了个password, 找出来谁搞的?</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git blame config.rb</span><br><span class="line">^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000  1) class Config</span><br><span class="line">70d00535 (Bruce Banner      2012-03-08 23:07:41 +0000  2)   attr_accessor :name, :password</span><br><span class="line">97bdd0cc (Spider Man        2012-03-08 23:08:15 +0000  3)   def initialize(name, password = nil, options = &#123;&#125;)</span><br><span class="line">^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000  4)     @name = name</span><br><span class="line">97bdd0cc (Spider Man        2012-03-08 23:08:15 +0000  5)     @password = password || &quot;i&lt;3evil&quot;</span><br><span class="line">00000000 (Not Committed Yet 2017-12-22 16:23:59 +0800  6)</span><br><span class="line">09409480 (Spider Man        2012-03-08 23:06:18 +0000  7)     if options[:downcase]</span><br><span class="line">09409480 (Spider Man        2012-03-08 23:06:18 +0000  8)       @name.downcase!</span><br><span class="line">09409480 (Spider Man        2012-03-08 23:06:18 +0000  9)     end</span><br><span class="line">70d00535 (Bruce Banner      2012-03-08 23:07:41 +0000 10)</span><br><span class="line">ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 11)     if options[:upcase]</span><br><span class="line">ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 12)       @name.upcase!</span><br><span class="line">ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 13)     end</span><br><span class="line">ffd39c2d (Gary Rennie       2012-03-08 23:08:58 +0000 14)</span><br><span class="line">^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000 15)   end</span><br><span class="line">^5e8863d (Gary Rennie       2012-03-08 23:05:24 +0000 16) end</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Who made the commit with the password? Spider Man</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>这个命令会详细列出该文件每行代码提交的哈希值, 提交的人和日期</p><h4 id="Level-31-branch"><a href="#Level-31-branch" class="headerlink" title="Level 31: branch"></a>Level 31: branch</h4><blockquote><p>You want to work on a piece of code that has the potential to break things, create the branch test_code.</p><p>你想实验一些代码, 但害怕有问题. 创建一个新分支test_code</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch test_code</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* master</span><br><span class="line">  test_code</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git branch xxx # 创建一个分支</span><br><span class="line">git branch # 列出所有分支</span><br></pre></td></tr></table></figure><h4 id="Level-32-checkout"><a href="#Level-32-checkout" class="headerlink" title="Level 32: checkout"></a>Level 32: checkout</h4><blockquote><p>Create and switch to a new branch called my_branch. You will need to create a branch like you did in the previous level.</p><p>创建一个新分支my_branch并切换到这个新分支</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch my_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git checkout my_branch</span><br><span class="line">Switched to branch &apos;my_branch&apos;</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">  master</span><br><span class="line">* my_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><strong>补充:</strong></p><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git checkout xxxBranch  # 检出一个分支</span><br><span class="line">git checkout xxxFile  # 之前讲过如何撤销进入暂存区的修改, 这个也可以</span><br><span class="line">git checkout -b xxx  # == git branch xxx + git checkout xxx</span><br><span class="line">git checkout - # 用于在最近的两个分支之间切换</span><br></pre></td></tr></table></figure><h4 id="Level-33-checkout-tag"><a href="#Level-33-checkout-tag" class="headerlink" title="Level 33: checkout_tag"></a>Level 33: checkout_tag</h4><blockquote><p>You need to fix a bug in the version 1.2 of your app. Checkout the tag <code>v1.2</code>.</p><p>你需要切换到<code>tag v1.2</code>上去修复一些Bug</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git tag</span><br><span class="line">v1.0</span><br><span class="line">v1.2</span><br><span class="line">v1.5</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git checkout v1.2</span><br><span class="line">Note: checking out &apos;v1.2&apos;.</span><br><span class="line"></span><br><span class="line">You are in &apos;detached HEAD&apos; state. You can look around, make experimental</span><br><span class="line">changes and commit them, and you can discard any commits you make in this</span><br><span class="line">state without impacting any branches by performing another checkout.</span><br><span class="line"></span><br><span class="line">If you want to create a new branch to retain commits you create, you may</span><br><span class="line">do so (now or later) by using -b with the checkout command again. Example:</span><br><span class="line"></span><br><span class="line">  git checkout -b new_branch_name</span><br><span class="line"></span><br><span class="line">HEAD is now at 060320d... Some more changes</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* (detached from v1.2)</span><br><span class="line">  master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><strong>注意:</strong> 从前面已经看到<code>git checkout</code>后面可以跟分之, 标签, 文件. 但是作用不通.</p><h4 id="Level-34-checkout-tag-over-branch"><a href="#Level-34-checkout-tag-over-branch" class="headerlink" title="Level 34: checkout_tag_over_branch"></a>Level 34: checkout_tag_over_branch</h4><blockquote><p>You need to fix a bug in the version 1.2 of your app. Checkout the tag <code>v1.2</code> (Note: There is also a branch named <code>v1.2</code>).</p><p>切换到<code>tag v1.2</code>上去修复一个bug(注意有一个分支也叫v1.2)</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git checkout tags/v1.2</span><br><span class="line">Note: checking out &apos;tags/v1.2&apos;.</span><br><span class="line"></span><br><span class="line">You are in &apos;detached HEAD&apos; state. You can look around, make experimental</span><br><span class="line">changes and commit them, and you can discard any commits you make in this</span><br><span class="line">state without impacting any branches by performing another checkout.</span><br><span class="line"></span><br><span class="line">If you want to create a new branch to retain commits you create, you may</span><br><span class="line">do so (now or later) by using -b with the checkout command again. Example:</span><br><span class="line"></span><br><span class="line">  git checkout -b new_branch_name</span><br><span class="line"></span><br><span class="line">HEAD is now at fc5edda... Some more changes</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>这样区分就好了.</p><h4 id="Level-35-branch-at"><a href="#Level-35-branch-at" class="headerlink" title="Level 35: branch_at"></a>Level 35: branch_at</h4><blockquote><p>You forgot to branch at the previous commit and made a commit on top of it. Create branch test_branch at the commit before the last.</p><p>你忘记在上次提交之前先创建一个分支, 那么创建一个test_branch在上次提交之前</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">03a7f2c Updating file1 again</span><br><span class="line">3bcda78 Updating file1</span><br><span class="line">3873d24 Adding file1</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch test_branch 3bcda78</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-36-delete-branch"><a href="#Level-36-delete-branch" class="headerlink" title="Level 36: delete_branch"></a>Level 36: delete_branch</h4><blockquote><p>You have created too many branches for your project. There is an old branch in your repo called ‘delete_me’, you should delete it.</p><p>删掉<code>delete_me</code>分支</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">  delete_me</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch -d delete_me</span><br><span class="line">Deleted branch delete_me (was b60afe2).</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-37-push-branch"><a href="#Level-37-push-branch" class="headerlink" title="Level 37: push_branch"></a>Level 37: push_branch</h4><blockquote><p>You’ve made some changes to a local branch and want to share it, but aren’t yet ready to merge it with the ‘master’ branch. Push only ‘test_branch’ to the remote repository.</p><p>你本地分支做了些修改想分享它, 但是不准备合并到master上. 所以把他推送到test_branch分支远程仓库上.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git remote</span><br><span class="line">origin</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* master</span><br><span class="line">  other_branch</span><br><span class="line">  test_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git push origin test_branch</span><br><span class="line">Counting objects: 7, done.</span><br><span class="line">Delta compression using up to 4 threads.</span><br><span class="line">Compressing objects: 100% (6/6), done.</span><br><span class="line">Writing objects: 100% (6/6), 572 bytes | 0 bytes/s, done.</span><br><span class="line">Total 6 (delta 3), reused 0 (delta 0)</span><br><span class="line">To /tmp/d20171222-302-aokpd0/.git</span><br><span class="line"> * [new branch]      test_branch -&gt; test_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-38-merge"><a href="#Level-38-merge" class="headerlink" title="Level 38: merge"></a>Level 38: merge</h4><blockquote><p>We have a file in the branch ‘feature’; Let’s merge it to the master branch.</p><p>feature分支上有个文件, 把它合并到master上</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">e12277f added file1</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log feature --oneline</span><br><span class="line">cc8ea5a added file2</span><br><span class="line">e12277f added file1</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">  feature</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git merge feature</span><br><span class="line">Updating e12277f..cc8ea5a</span><br><span class="line">Fast-forward</span><br><span class="line"> file2 | 0</span><br><span class="line"> 1 file changed, 0 insertions(+), 0 deletions(-)</span><br><span class="line"> create mode 100644 file2</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">cc8ea5a added file2</span><br><span class="line">e12277f added file1</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>分支测试完成后就可以合并到主干, 主干上也会记录对应的日志.</p><h4 id="Level-39-fetch"><a href="#Level-39-fetch" class="headerlink" title="Level 39: fetch"></a>Level 39: fetch</h4><blockquote><p>Looks like a new branch was pushed into our remote repository. Get the changes without merging them with the local repository</p><p>有一个新的分支推送到远程仓库了, 得到它但是不要合并到你的本地仓库</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch -r</span><br><span class="line">  origin/master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git fetch</span><br><span class="line">remote: Counting objects: 3, done.</span><br><span class="line">remote: Compressing objects: 100% (2/2), done.</span><br><span class="line">remote: Total 2 (delta 0), reused 0 (delta 0)</span><br><span class="line">Unpacking objects: 100% (2/2), done.</span><br><span class="line">From /tmp/d20171222-797-1165a5c/</span><br><span class="line"> * [new branch]      new_branch -&gt; origin/new_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch -r</span><br><span class="line">  origin/master</span><br><span class="line">  origin/new_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>为什么不用<code>git pull</code>呢, 因为它不仅会拉取远程代码, 还会合并到本地代码, 相当于<code>git fetch</code>+<code>git merge</code></p><p>在 <code>git fetch</code> 之后用 <code>git branch -r</code> 查看时会发现新分支的名称</p><h4 id="Level-40-rebase"><a href="#Level-40-rebase" class="headerlink" title="Level 40: rebase"></a>Level 40: rebase</h4><blockquote><p>We are using a git rebase workflow and the feature branch is ready to go into master. Let’s rebase the feature branch onto our master branch.</p><p>我们使用了git rebase工作流, 并准备把feature分支合并到master. 现在rebase feature分支到master分之上吧.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">  feature</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git checkout feature</span><br><span class="line">Switched to branch &apos;feature&apos;</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">ed0fdcf add feature</span><br><span class="line">a78bcab init commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">98205e9 add content</span><br><span class="line">a78bcab init commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git rebase master</span><br><span class="line">First, rewinding head to replay your work on top of it...</span><br><span class="line">Applying: add feature</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">98205e9 add content</span><br><span class="line">a78bcab init commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">967920c add feature</span><br><span class="line">98205e9 add content</span><br><span class="line">a78bcab init commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>参考: <a href="https://segmentfault.com/a/1190000005937408" target="_blank" rel="noopener">Git Rebase原理以及黄金准则详解</a></p><h4 id="Level-41-rebase-onto"><a href="#Level-41-rebase-onto" class="headerlink" title="Level 41: rebase_onto"></a>Level 41: rebase_onto</h4><blockquote><p>You have created your branch from <code>wrong_branch</code> and already made some commits, and you realise that you needed to create your branch from <code>master</code>. Rebase your commits onto <code>master</code> branch so that you don’t have <code>wrong_branch</code> commits.</p><p>你错误的从<code>wrong_branch</code>上创建了一个分支, 并且有了一些提交, 但是你意识到你应该是从<code>master</code>上创建分支, 现在rebase你的提交到<code>master</code>分支上去, 并且不保留<code>wrong_branch</code>的提交.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">  master</span><br><span class="line">* readme-update</span><br><span class="line">  wrong_branch</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">3d8ad8d Create authors file</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log wrong_branch --oneline</span><br><span class="line">a2c5c42 Wrong changes</span><br><span class="line">3d8ad8d Create authors file</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">9c959f1 Add `Install` header in readme</span><br><span class="line">082624b Add `About` header in readme</span><br><span class="line">73dbf72 Add app name in readme</span><br><span class="line">a2c5c42 Wrong changes</span><br><span class="line">3d8ad8d Create authors file</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git rebase --onto master wrong_branch readme-update</span><br><span class="line">First, rewinding head to replay your work on top of it...</span><br><span class="line">Applying: Add app name in readme</span><br><span class="line">Applying: Add `About` header in readme</span><br><span class="line">Applying: Add `Install` header in readme</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">3d8ad8d Create authors file</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log wrong_branch --oneline</span><br><span class="line">a2c5c42 Wrong changes</span><br><span class="line">3d8ad8d Create authors file</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">b113760 Add `Install` header in readme</span><br><span class="line">809fc39 Add `About` header in readme</span><br><span class="line">7adf9cd Add app name in readme</span><br><span class="line">3d8ad8d Create authors file</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><code>wrong_branch</code>和<code>master</code>分支的日志都没有变, 注意看<code>readme-update</code>的日志变化.</p><p><strong>补充:</strong></p><p>摘一段官网的内容:</p><blockquote><p>First let’s assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">o---o---o---o---o  master</span><br><span class="line">     \</span><br><span class="line">      o---o---o---o---o  next</span><br><span class="line">                       \</span><br><span class="line">                        o---o---o  topic</span><br></pre></td></tr></table></figure><blockquote><p>We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master branch. We want our tree to look like this:</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">o---o---o---o---o  master</span><br><span class="line">    |            \</span><br><span class="line">    |             o&apos;--o&apos;--o&apos;  topic</span><br><span class="line">     \</span><br><span class="line">      o---o---o---o---o  next</span><br></pre></td></tr></table></figure><blockquote><p>We can get this using the following command:<code>git rebase –onto master next topic</code></p></blockquote><h4 id="Level-42-repack"><a href="#Level-42-repack" class="headerlink" title="Level 42: repack"></a>Level 42: repack</h4><blockquote><p>Optimise how your repository is packaged ensuring that redundant packs are removed.</p><p>优化仓库的打包, 确保删除掉重复多余的包</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# ls .git/objects/</span><br><span class="line">4d  80  e6  info  pack</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git repack -d</span><br><span class="line">Counting objects: 3, done.</span><br><span class="line">Writing objects: 100% (3/3), done.</span><br><span class="line">Total 3 (delta 0), reused 0 (delta 0)</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# ls .git/objects/</span><br><span class="line">info  pack</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# ls .git/objects/pack/</span><br><span class="line">pack-830ef7487354a6468143f53dd19ee16c25fc2837.idx  pack-830ef7487354a6468143f53dd19ee16c25fc2837.pack</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-43-cherry-pick"><a href="#Level-43-cherry-pick" class="headerlink" title="Level 43: cherry-pick"></a>Level 43: cherry-pick</h4><blockquote><p>Your new feature isn’t worth the time and you’re going to delete it. But it has one commit that fills in <code>README</code>file, and you want this commit to be on the master as well.</p><p>你的新功能废了你要删除它! 但是其中有一次README的提交还是有用的, 你把这次提交合并到主干上.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">* master</span><br><span class="line">  new-feature</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log new-feature --oneline</span><br><span class="line">ea2a47c some small fixes</span><br><span class="line">4a1961b Fixed feature</span><br><span class="line">ca32a6d Filled in README.md with proper input</span><br><span class="line">58a8c8e Added a stub for the feature</span><br><span class="line">ea3dbcc Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">6edea63 Added fancy branded output</span><br><span class="line">232d266 Renamed project.js -&gt; herdcore-math.js</span><br><span class="line">b30c6a9 Added a hardcore math module</span><br><span class="line">ea3dbcc Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git cherry</span><br><span class="line">cherry        cherry-pick</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git cherry</span><br><span class="line">cherry        cherry-pick</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git cherry-pick ca32a6d</span><br><span class="line">[master 25034ea] Filled in README.md with proper input</span><br><span class="line"> Author: Andrey &lt;aslushnikov@gmail.com&gt;</span><br><span class="line"> 1 file changed, 1 insertion(+), 2 deletions(-)</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">25034ea Filled in README.md with proper input</span><br><span class="line">6edea63 Added fancy branded output</span><br><span class="line">232d266 Renamed project.js -&gt; herdcore-math.js</span><br><span class="line">b30c6a9 Added a hardcore math module</span><br><span class="line">ea3dbcc Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><code>git cherry-pick hash-code</code>: 摘樱桃. 可以选取一个分支上某次提交的哈希值来合并到主线上.</p><h4 id="Level-44-grep"><a href="#Level-44-grep" class="headerlink" title="Level 44: grep"></a>Level 44: grep</h4><blockquote><p>Your project’s deadline approaches, you should evaluate how many TODOs are left in your code.</p><p>找下项目里还有多少待办事项(TODOs)</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git grep TODO</span><br><span class="line">app.rb:# TODO Make site url variable.</span><br><span class="line">app.rb:# TODO Make API version variable.</span><br><span class="line">app.rb:# TODO Redirecting queries could be useful.</span><br><span class="line">config.rb:    # TODO Move password to a configuration file.</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">How many items are there in your todolist? 4</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git grep xxx # 全项目查找</span><br><span class="line">git grep xxx file-name # 指定文件查找</span><br></pre></td></tr></table></figure><h4 id="Level-45-rename-commit"><a href="#Level-45-rename-commit" class="headerlink" title="Level 45: rename_commit"></a>Level 45: rename_commit</h4><blockquote><p>Correct the typo in the message of your first (non-root) commit.</p><p>修正第一次提交的拼写错误</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">5da15a1 Second commit</span><br><span class="line">d1c06bd First coommit</span><br><span class="line">2b08caa Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git rebase -i 2b08caa</span><br><span class="line">[detached HEAD ac4092f] First commit</span><br><span class="line"> 1 file changed, 0 insertions(+), 0 deletions(-)</span><br><span class="line"> create mode 100644 file1</span><br><span class="line">Successfully rebased and updated refs/heads/master.</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">208de39 Second commit</span><br><span class="line">ac4092f First commit</span><br><span class="line">2b08caa Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><strong>补充:</strong></p><p><code>git rebase -i hash-code</code>:</p><p>后面加了<code>-i</code>参数后就不再是分支合并的意思了. <code>-i</code>表示交互, 后面跟上提交的哈希码, 可以修改历史的提交.</p><p>执行该命令后, 会启动文本编辑器, 并在其中显示每次提交的记录信息(从前到后显示).</p><p>每行记录前面会有一个标识, 表示进行什么修改操作:</p><p><strong>Commands:</strong></p><ul><li>p, pick: 表示执行此次提交</li><li>r, reword: 表示执行此次提交，但要修改备注内容</li><li>e, edit: 表示可以修改此次提交，比如再追加文件或修改文件</li><li>s, squash : 表示把此次提交的内容合并到上次提交中，备注内容也合并到上次提交中</li><li>f, fixup : 和 “squash” 类似，但会丢弃掉此次备注内容</li><li>x, exec : 执行命令行下的命令</li><li>drop : 删除此次提交</li></ul><p>本关用的就是reword.</p><h4 id="Level-46-squash"><a href="#Level-46-squash" class="headerlink" title="Level 46: squash"></a>Level 46: squash</h4><blockquote><p>You have committed several times but would like all those changes to be one commit.</p><p>把多次提交合并成一次</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">a68644a Updating README (squash this commit into Adding README)</span><br><span class="line">712a031 Updating README (squash this commit into Adding README)</span><br><span class="line">da9df2a Updating README (squash this commit into Adding README)</span><br><span class="line">e799cb3 Adding README</span><br><span class="line">04a03cf Initial Commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git rebase -i 04a03cf</span><br><span class="line">[detached HEAD 63c098c] Adding README</span><br><span class="line"> 1 file changed, 3 insertions(+)</span><br><span class="line"> create mode 100644 README</span><br><span class="line">Successfully rebased and updated refs/heads/master.</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">63c098c Adding README</span><br><span class="line">04a03cf Initial Commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>本关用的就是squash.</p><h4 id="Level-47-merge-squash"><a href="#Level-47-merge-squash" class="headerlink" title="Level 47: merge_squash"></a>Level 47: merge_squash</h4><blockquote><p>Merge all commits from the long-feature-branch as a single commit.</p><p>把<code>long-feature-branch</code>上的多次提交合并到主干上的一次提交</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git branch</span><br><span class="line">  long-feature-branch</span><br><span class="line">* master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">b79bd86 Second commit</span><br><span class="line">24289dd First commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log long-feature-branch  --oneline</span><br><span class="line">0a1ccc1 Time</span><br><span class="line">36fb820 Takes</span><br><span class="line">cef0b75 Developing new features</span><br><span class="line">24289dd First commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git merge long-feature-branch --squash</span><br><span class="line">Squash commit -- not updating HEAD</span><br><span class="line">Automatic merge went well; stopped before committing as requested</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git commit -m &quot;merge from long-fxxxx-branch&quot;</span><br><span class="line">[master 18b8931] merge from long-fxxxx-branch</span><br><span class="line"> 1 file changed, 3 insertions(+)</span><br><span class="line"> create mode 100644 file3</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log master --oneline</span><br><span class="line">18b8931 merge from long-fxxxx-branch</span><br><span class="line">b79bd86 Second commit</span><br><span class="line">24289dd First commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>通常分支上会有很多个提交, 在合并到主干上时也会给主干带过去多次提交记录, 这样不便于追踪.</p><p>所以使用<code>git merge xxbranch_name --squash</code>命令把分支的多次提交搞成一次.</p><p>注意使用完合并之后, 需要在<code>commit</code>一下, 并写上注释信息. (不加<code>--squash</code>时会自动commit).</p><h4 id="Level-48-reorder"><a href="#Level-48-reorder" class="headerlink" title="Level 48: reorder"></a>Level 48: reorder</h4><blockquote><p>You have committed several times but in the wrong order. Please reorder your commits.</p><p>调整提交顺序</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">ef9e60e Second commit</span><br><span class="line">54c5e74 Third commit</span><br><span class="line">b424f5a First commit</span><br><span class="line">b435e3c Initial Setup</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git rebase -i b435e3c</span><br><span class="line">Successfully rebased and updated refs/heads/master.</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">94b9586 Third commit</span><br><span class="line">866d552 Second commit</span><br><span class="line">b424f5a First commit</span><br><span class="line">b435e3c Initial Setup</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-49-bisect"><a href="#Level-49-bisect" class="headerlink" title="Level 49: bisect"></a>Level 49: bisect</h4><blockquote><p>A bug was introduced somewhere along the way. You know that running “ruby prog.rb 5” should output 15. You can also run “make test”. What are the first 7 chars of the hash of the commit that introduced the bug.</p><p>在开发过程中引入了一个 bug。已知运行 “ruby prog.rb 5” 应该输入 15，你也可以运行 “make test” 进行测试。你需要确定引入 bug 的那次提交的哈希值的前7位。</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">12628f4 Another Commit</span><br><span class="line">9795761 Another Commit</span><br><span class="line">028763b Another Commit</span><br><span class="line">888386c Another Commit</span><br><span class="line">bb736dd Another Commit</span><br><span class="line">18ed2ac Another Commit</span><br><span class="line">5db7a7c Another Commit</span><br><span class="line">7c03a99 Another Commit</span><br><span class="line">9f54462 Another Commit</span><br><span class="line">5d1eb75 Another Commit</span><br><span class="line">fdbfc0d Another Commit</span><br><span class="line">a530e7e Another Commit</span><br><span class="line">ccddb96 Another Commit</span><br><span class="line">2e1735d Another Commit</span><br><span class="line">ffb097e Another Commit</span><br><span class="line">e060c0d Another Commit</span><br><span class="line">49774ea Another Commit</span><br><span class="line">8c992af Another Commit</span><br><span class="line">80a9b3d Another Commit</span><br><span class="line">f608824 First commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect start</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect good f608824</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect bad 12628f4</span><br><span class="line">Bisecting: 9 revisions left to test after this (roughly 3 steps)</span><br><span class="line">[fdbfc0d403e5ac0b2659cbfa2cbb061fcca0dc2a] Another Commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# make test</span><br><span class="line">ruby prog.rb 5 | ruby test.rb</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect good</span><br><span class="line">Bisecting: 4 revisions left to test after this (roughly 2 steps)</span><br><span class="line">[18ed2ac1522a014412d4303ce7c8db39becab076] Another Commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# make test</span><br><span class="line">ruby prog.rb 5 | ruby test.rb</span><br><span class="line">make: *** [test] Error 1</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect bad</span><br><span class="line">Bisecting: 2 revisions left to test after this (roughly 1 step)</span><br><span class="line">[9f54462abbb991b167532929b34118113aa6c52e] Another Commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# make test</span><br><span class="line">ruby prog.rb 5 | ruby test.rb</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect good</span><br><span class="line">Bisecting: 0 revisions left to test after this (roughly 1 step)</span><br><span class="line">[5db7a7cb90e745e2c9dbdd84810ccc7d91d92e72] Another Commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# make test</span><br><span class="line">ruby prog.rb 5 | ruby test.rb</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git bisect good</span><br><span class="line">18ed2ac1522a014412d4303ce7c8db39becab076 is the first bad commit</span><br><span class="line">commit 18ed2ac1522a014412d4303ce7c8db39becab076</span><br><span class="line">Author: Robert Bittle &lt;guywithnose@gmail.com&gt;</span><br><span class="line">Date:   Mon Apr 23 06:52:10 2012 -0400</span><br><span class="line"></span><br><span class="line">    Another Commit</span><br><span class="line"></span><br><span class="line">:100644 100644 917e70054c8f4a4a79a8e805c0e1601b455ad236 7562257b8e6446686ffc43a2386c50c254365020 M      prog.rb</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">What are the first 7 characters of the hash of the commit that introduced the bug? 18ed2ac1522a014412d4303ce7c8db39becab076</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>对我没用.. 略</p><h4 id="Level-50-stage-lines"><a href="#Level-50-stage-lines" class="headerlink" title="Level 50: stage_lines"></a>Level 50: stage_lines</h4><blockquote><p>You’ve made changes within a single file that belong to two different features, but neither of the changes are yet staged. Stage only the changes belonging to the first feature.</p><p>一个文件里有两个功能, 现在只想把其中一个功能提交到暂存区.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git status -s</span><br><span class="line"> M feature.rb</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git diff feature.rb</span><br><span class="line">diff --git a/feature.rb b/feature.rb</span><br><span class="line">index 1a271e9..4a80dda 100644</span><br><span class="line">--- a/feature.rb</span><br><span class="line">+++ b/feature.rb</span><br><span class="line">@@ -1 +1,3 @@</span><br><span class="line"> this is the class of my feature</span><br><span class="line">+This change belongs to the first feature</span><br><span class="line">+This change belongs to the second feature</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git add feature.rb --edit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git status -s</span><br><span class="line">MM feature.rb</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git diff feature.rb</span><br><span class="line">diff --git a/feature.rb b/feature.rb</span><br><span class="line">index 3bccd0e..4a80dda 100644</span><br><span class="line">--- a/feature.rb</span><br><span class="line">+++ b/feature.rb</span><br><span class="line">@@ -1,2 +1,3 @@</span><br><span class="line"> this is the class of my feature</span><br><span class="line"> This change belongs to the first feature</span><br><span class="line">+This change belongs to the second feature</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><code>git add file_name --edit</code>会在添加文件时打开编辑器, 并显示文件diff结果. 可以根据编辑的结果进行add操作.</p><h4 id="Level-51-find-old-branch"><a href="#Level-51-find-old-branch" class="headerlink" title="Level 51: find_old_branch"></a>Level 51: find_old_branch</h4><blockquote><p>You have been working on a branch but got distracted by a major issue and forgot the name of it. Switch back to that branch.</p><p>你忘了刚才时在哪个分支上工作了, 找到它. 切换过去</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git reflog</span><br><span class="line">894a16d HEAD@&#123;0&#125;: commit: commit another todo</span><br><span class="line">6876e5b HEAD@&#123;1&#125;: checkout: moving from solve_world_hunger to kill_the_batman</span><br><span class="line">324336a HEAD@&#123;2&#125;: commit: commit todo</span><br><span class="line">6876e5b HEAD@&#123;3&#125;: checkout: moving from blowup_sun_for_ransom to solve_world_hunger</span><br><span class="line">6876e5b HEAD@&#123;4&#125;: checkout: moving from kill_the_batman to blowup_sun_for_ransom</span><br><span class="line">6876e5b HEAD@&#123;5&#125;: checkout: moving from cure_common_cold to kill_the_batman</span><br><span class="line">6876e5b HEAD@&#123;6&#125;: commit (initial): initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git checkout solve_world_hunger</span><br><span class="line">Switched to branch &apos;solve_world_hunger&apos;</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p><code>git reflog</code>不光记录了Commit信息, 还记录了分支切换的信息.</p><h4 id="Level-52-revert"><a href="#Level-52-revert" class="headerlink" title="Level 52: revert"></a>Level 52: revert</h4><blockquote><p>You have committed several times but want to undo the middle commit. All commits have been pushed, so you can’t change existing history.</p><p>你提交了很多次, 而且已经推送到服务器上了,所以你不能改变已经存在的历史. 你想取消中间的某次提交.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">498b9be Second commit</span><br><span class="line">5a42119 Bad commit</span><br><span class="line">4d925f6 First commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git revert 5a42119 --no-edit</span><br><span class="line">[master c608236] Revert &quot;Bad commit&quot;</span><br><span class="line"> 1 file changed, 0 insertions(+), 0 deletions(-)</span><br><span class="line"> delete mode 100644 file3</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">c608236 Revert &quot;Bad commit&quot;</span><br><span class="line">498b9be Second commit</span><br><span class="line">5a42119 Bad commit</span><br><span class="line">4d925f6 First commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><p>既然不能改变历史, 那就用<code>git revert</code>增加一次取消的逆处理.</p><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git revert hash-code # 调用文本编辑器让你编写注释</span><br><span class="line">git revert hash-code --no-edit # 自动生成注释</span><br></pre></td></tr></table></figure><h4 id="Level-53-restore"><a href="#Level-53-restore" class="headerlink" title="Level 53: restore"></a>Level 53: restore</h4><blockquote><p>You decided to delete your latest commit by running <code>git reset --hard HEAD^</code>. (Not a smart thing to do.) You then change your mind, and want that commit back. Restore the deleted commit.</p><p>你用<code>git reset --hard HEAD^</code>删掉了最后一次提交(傻), 然后你改变主意了, 想回退恢复那条被删除的提交.</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">d56c44f First commit</span><br><span class="line">9fd667b Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git reflog</span><br><span class="line">d56c44f HEAD@&#123;0&#125;: reset: moving to HEAD^</span><br><span class="line">dfabe57 HEAD@&#123;1&#125;: commit: Restore this commit</span><br><span class="line">d56c44f HEAD@&#123;2&#125;: commit: First commit</span><br><span class="line">9fd667b HEAD@&#123;3&#125;: commit (initial): Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git reset --hard dfabe57</span><br><span class="line">HEAD is now at dfabe57 Restore this commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git log --oneline</span><br><span class="line">dfabe57 Restore this commit</span><br><span class="line">d56c44f First commit</span><br><span class="line">9fd667b Initial commit</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-54-conflict"><a href="#Level-54-conflict" class="headerlink" title="Level 54: conflict"></a>Level 54: conflict</h4><blockquote><p>You need to merge mybranch into the current branch (master). But there may be some incorrect changes in mybranch which may cause conflicts. Solve any merge-conflicts you come across and finish the merge.</p><p>你要合并mybranch分支到当前分支master, 可能有冲突, 解决!</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git merge mybranch</span><br><span class="line">Auto-merging poem.txt</span><br><span class="line">CONFLICT (content): Merge conflict in poem.txt</span><br><span class="line">Automatic merge failed; fix conflicts and then commit the result.</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# vim poem.txt</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git status</span><br><span class="line"># On branch master</span><br><span class="line"># You have unmerged paths.</span><br><span class="line">#   (fix conflicts and run &quot;git commit&quot;)</span><br><span class="line">#</span><br><span class="line"># Unmerged paths:</span><br><span class="line">#   (use &quot;git add &lt;file&gt;...&quot; to mark resolution)</span><br><span class="line">#</span><br><span class="line">#       both modified:      poem.txt</span><br><span class="line">#</span><br><span class="line">no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git add poem.txt</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# git commit -m &quot;merge mybranch to master&quot;</span><br><span class="line">[master 7c3ba83] merge mybranch to master</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-55-submodule"><a href="#Level-55-submodule" class="headerlink" title="Level 55: submodule"></a>Level 55: submodule</h4><blockquote><p>You want to include the files from the following repo: <code>https://github.com/jackmaney/githug-include-me</code>into a the folder <code>./githug-include-me</code>. Do this without cloning the repo or copying the files from the repo into this repo.</p><p>你想把 <code>https://github.com/jackmaney/githug-include-me</code> 这个仓库的代码引入到自己项目的 <code>./githug-include-me</code> 目录，这个方法不需要克隆第三方仓库，也不需要把第三方仓库的文件复制到你的项目中。</p></blockquote><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@pipeline-cloud-test02 git_hug]# git submodule add https://github.com/jackmaney/githug-include-me</span><br><span class="line">Cloning into &apos;githug-include-me&apos;...</span><br><span class="line">remote: Counting objects: 9, done.</span><br><span class="line">remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 9</span><br><span class="line">Unpacking objects: 100% (9/9), done.</span><br><span class="line">[root@pipeline-cloud-test02 git_hug]# githug</span><br><span class="line">********************************************************************************</span><br><span class="line">*                                    Githug                                    *</span><br><span class="line">********************************************************************************</span><br><span class="line">Congratulations, you have solved the level!</span><br></pre></td></tr></table></figure><h4 id="Level-56-contribute"><a href="#Level-56-contribute" class="headerlink" title="Level 56: contribute"></a>Level 56: contribute</h4><blockquote><p>This is the final level, the goal is to contribute to this repository by making a pull request on GitHub. Please note that this level is designed to encourage you to add a valid contribution to Githug, not testing your ability to create a pull request. Contributions that are likely to be accepted are levels, bug fixes and improved documentation.</p></blockquote><p>最后一关, 是让你去GitHub贡献一个request.</p><p>其实到这已经全部通关!</p></div><ul class="post-copyright"><li><strong>本文标题：</strong><a href="https://xiefayang.com/2017/12/25/通关Githug(二)/">通关Githug(二)</a></li><li><strong>本文作者：</strong><a href="https://xiefayang.com">i蝸居年華_谢谢谢</a></li><li><strong>本文链接：</strong><a href="https://xiefayang.com/2017/12/25/通关Githug(二)/">https://xiefayang.com/2017/12/25/通关Githug(二)/</a></li><li><strong>发布时间：</strong>2017-12-25</li><li><strong>版权声明：</strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li></ul><div class="level is-size-7 is-uppercase"><div class="level-start"><div class="level-item"> <span class="is-size-6 has-text-grey has-mr-7">#</span> <a class="has-link-grey -link" href="/tags/Git/">Git</a></div></div></div><div class="social-share"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/js/social-share.min.js"></script></div></div><div class="card"><div class="card-content"><h3 class="menu-label has-text-centered">坚持原创技术分享，您的支持将鼓励我继续创作！</h3><div class="buttons is-centered"><a class="button is-info donate"><span class="icon is-small"><i class="fab fa-alipay"></i></span> <span>支付宝</span><div class="qrcode"><img src="/images/no2.jpg" alt="支付宝"></div></a><a class="button is-success donate"><span class="icon is-small"><i class="fab fa-weixin"></i></span> <span>微信</span><div class="qrcode"><img src="/images/no.gif" alt="微信"></div></a></div></div></div><div class="card card-transparent"><div class="level post-navigation is-flex-wrap is-mobile"><div class="level-start"><a class="level level-item has-link-grey article-nav-prev" href="/2018/01/01/Elasticsearch初探/"><i class="level-item fas fa-chevron-left"></i> <span class="level-item">Elasticsearch初探</span></a></div><div class="level-end"> <a class="level level-item has-link-grey article-nav-next" href="/2017/12/25/通关Githug(一)/"><span class="level-item">通关Githug(一)</span><i class="level-item fas fa-chevron-right"></i></a></div></div></div><div class="card"><div class="card-content"><h3 class="title is-5 has-text-weight-normal">评论</h3><div id="valine-thread" class="content"></div><script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script><script src="/js/Valine.min.js"></script><script>new Valine({el:"#valine-thread",notify:!1,verify:!1,app_id:"yVPV2fAKC1B90Xnh2JjuPEAb-gzGzoHsz",app_key:"1i9DgF7j75Uq6OuM23etjjE9",placeholder:"Just go go, 支持Markdown~"})</script></div></div></div><div class="column is-4-tablet is-4-desktop is-3-widescreen has-order-1 column-left"><div class="card widget"><div class="card-content"><nav class="level"><div class="level-item has-text-centered"><div> <img class="image is-128x128 has-mb-6" src="/images/avatar.png" alt="i蝸居年華_谢谢谢" style="border-radius:50%"><p class="is-size-4 is-block"> i蝸居年華_谢谢谢</p><p class="is-size-6 is-block"> Just for fun</p><p class="is-size-6 is-flex is-flex-center has-text-grey"><i class="fas fa-map-marker-alt has-mr-7"></i> <span>Beijing, China</span></p></div></div></nav><nav class="level is-mobile"><div class="level-item has-text-centered is-marginless"><div><p class="heading"> 文章</p><p class="title has-text-weight-normal"> 49</p></div></div><div class="level-item has-text-centered is-marginless"><div><p class="heading"> 分类</p><p class="title has-text-weight-normal"> 13</p></div></div><div class="level-item has-text-centered is-marginless"><div><p class="heading"> 标签</p><p class="title has-text-weight-normal"> 32</p></div></div></nav><div class="level"> <a class="level-item button is-link is-rounded" href="https://github.com/thank037" target="_blank">关注我</a></div><div class="level is-mobile"> <a class="level-item button is-white is-marginless" target="_blank" title="github" href="https://github.com/thank037" name><img src="/images/github.svg" style="width:20px;height:20px"></a> <a class="level-item button is-white is-marginless" target="_blank" title="gitee" href="https://gitee.com/thank037" name><img src="/images/gitee.svg" style="width:20px;height:20px"></a> <a class="level-item button is-white is-marginless" target="_blank" title="weibo" href="https://weibo.com/u/2139090054" name><img src="/images/weibo.svg" style="width:20px;height:20px"></a> <a class="level-item button is-white is-marginless" target="_blank" title="email" href="mailto:coderthank@163.com" name><img src="/images/email.svg" style="width:20px;height:20px"></a></div></div></div><div class="card widget column-left is-sticky" id="toc"><div class="card-content"><div class="menu"><h3 class="menu-label"> 文章目录</h3><ul class="menu-list"><li> <a class="is-flex" href="#关卡列表"><span class="has-mr-6">1</span> <span>关卡列表</span></a></li><li> <a class="is-flex" href="#Level-30-blame"><span class="has-mr-6">2</span> <span>Level 30: blame</span></a></li><li> <a class="is-flex" href="#Level-31-branch"><span class="has-mr-6">3</span> <span>Level 31: branch</span></a></li><li> <a class="is-flex" href="#Level-32-checkout"><span class="has-mr-6">4</span> <span>Level 32: checkout</span></a></li><li> <a class="is-flex" href="#Level-33-checkout-tag"><span class="has-mr-6">5</span> <span>Level 33: checkout_tag</span></a></li><li> <a class="is-flex" href="#Level-34-checkout-tag-over-branch"><span class="has-mr-6">6</span> <span>Level 34: checkout_tag_over_branch</span></a></li><li> <a class="is-flex" href="#Level-35-branch-at"><span class="has-mr-6">7</span> <span>Level 35: branch_at</span></a></li><li> <a class="is-flex" href="#Level-36-delete-branch"><span class="has-mr-6">8</span> <span>Level 36: delete_branch</span></a></li><li> <a class="is-flex" href="#Level-37-push-branch"><span class="has-mr-6">9</span> <span>Level 37: push_branch</span></a></li><li> <a class="is-flex" href="#Level-38-merge"><span class="has-mr-6">10</span> <span>Level 38: merge</span></a></li><li> <a class="is-flex" href="#Level-39-fetch"><span class="has-mr-6">11</span> <span>Level 39: fetch</span></a></li><li> <a class="is-flex" href="#Level-40-rebase"><span class="has-mr-6">12</span> <span>Level 40: rebase</span></a></li><li> <a class="is-flex" href="#Level-41-rebase-onto"><span class="has-mr-6">13</span> <span>Level 41: rebase_onto</span></a></li><li> <a class="is-flex" href="#Level-42-repack"><span class="has-mr-6">14</span> <span>Level 42: repack</span></a></li><li> <a class="is-flex" href="#Level-43-cherry-pick"><span class="has-mr-6">15</span> <span>Level 43: cherry-pick</span></a></li><li> <a class="is-flex" href="#Level-44-grep"><span class="has-mr-6">16</span> <span>Level 44: grep</span></a></li><li> <a class="is-flex" href="#Level-45-rename-commit"><span class="has-mr-6">17</span> <span>Level 45: rename_commit</span></a></li><li> <a class="is-flex" href="#Level-46-squash"><span class="has-mr-6">18</span> <span>Level 46: squash</span></a></li><li> <a class="is-flex" href="#Level-47-merge-squash"><span class="has-mr-6">19</span> <span>Level 47: merge_squash</span></a></li><li> <a class="is-flex" href="#Level-48-reorder"><span class="has-mr-6">20</span> <span>Level 48: reorder</span></a></li><li> <a class="is-flex" href="#Level-49-bisect"><span class="has-mr-6">21</span> <span>Level 49: bisect</span></a></li><li> <a class="is-flex" href="#Level-50-stage-lines"><span class="has-mr-6">22</span> <span>Level 50: stage_lines</span></a></li><li> <a class="is-flex" href="#Level-51-find-old-branch"><span class="has-mr-6">23</span> <span>Level 51: find_old_branch</span></a></li><li> <a class="is-flex" href="#Level-52-revert"><span class="has-mr-6">24</span> <span>Level 52: revert</span></a></li><li> <a class="is-flex" href="#Level-53-restore"><span class="has-mr-6">25</span> <span>Level 53: restore</span></a></li><li> <a class="is-flex" href="#Level-54-conflict"><span class="has-mr-6">26</span> <span>Level 54: conflict</span></a></li><li> <a class="is-flex" href="#Level-55-submodule"><span class="has-mr-6">27</span> <span>Level 55: submodule</span></a></li><li> <a class="is-flex" href="#Level-56-contribute"><span class="has-mr-6">28</span> <span>Level 56: contribute</span></a></li></ul></div></div></div><div class="column-right-shadow is-hidden-widescreen is-sticky"></div></div></div></div></section><footer class="footer"><div class="container"><div class="level"><div class="level-start has-text-centered-mobile"> <a class="footer-logo is-block has-mb-6" href="/">i蝸居年華_谢谢谢</a><p class="is-size-7"> &copy; 2016—2021 i蝸居年華_谢谢谢&nbsp; 由<a href="http://hexo.io/" target="_blank">Hexo</a> 强力驱动<br> <span id="busuanzi_container_site_uv">您是第<span id="busuanzi_value_site_uv">0</span>个访客</span></p></div><div class="level-end"><div class="field has-addons is-flex-center-mobile has-mt-5-mobile is-flex-wrap is-flex-middle"><p class="control"><a class="button is-white is-large" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a></p><p class="control"><a class="button is-white is-large" target="_blank" title="Attribution 4.0 International" href="https://creativecommons.org/licenses/by/4.0/"><i class="fab fa-creative-commons-by"></i></a></p><p class="control"><a class="button is-white is-large" target="_blank" title="Download on GitHub" href="https://github.com/thank037"><i class="fab fa-github"></i></a></p></div></div></div></div></footer><script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script><script>moment.locale("zh-CN")</script><script src="/js/animation.js"></script><script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer="defer"></script><script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer="defer"></script><script src="/js/gallery.js" defer="defer"></script><div id="outdated"><h6>Your browser is out-of-date!</h6><p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update my browser now</a></p><p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p></div><script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer="defer"></script><script>document.addEventListener("DOMContentLoaded",function(){outdatedBrowser({bgColor:"#f25648",color:"#ffffff",lowerThan:"flex"})})</script><script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer="defer"></script><script>document.addEventListener("DOMContentLoaded",function(){MathJax.Hub.Config({"HTML-CSS":{matchFontHeight:!1},SVG:{matchFontHeight:!1},CommonHTML:{matchFontHeight:!1},tex2jax:{inlineMath:[["$","$"],["\\(","\\)"]]}})})</script><a id="back-to-top" title="回到顶端" href="javascript:;"><i class="fas fa-chevron-up"></i></a><script src="/js/back-to-top.js" defer="defer"></script><script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer="defer"></script><script src="/js/clipboard.js" defer="defer"></script><script src="/js/main.js" defer="defer"></script><div class="searchbox ins-search"><div class="searchbox-container ins-search-container"><div class="searchbox-input-wrapper"> <input type="text" class="searchbox-input ins-search-input" placeholder="全文搜索站内文章~"><span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span></div><div class="searchbox-result-wrapper ins-section-wrapper"><div class="ins-section-container"></div></div></div></div><script>window.INSIGHT_CONFIG={TRANSLATION:{POSTS:"文章",PAGES:"页面",CATEGORIES:"分类",TAGS:"标签",UNTITLED:"(无标题)"},CONTENT_URL:"/content.json"}</script><script src="/js/insight.js" defer="defer"></script><link rel="stylesheet" href="/css/search.css"><link rel="stylesheet" href="/css/insight.css"><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,debug:!1,model:{jsonPath:"/live2dw/assets/hijiki.model.json"},display:{position:"right",width:150,height:300,mobile:{show:!0},react:{opacity:.7}},log:!1})</script></body></html>